package hc.server.data.screen;

import hc.core.ContextManager;
import hc.core.IConstant;
import hc.core.L;
import hc.core.MsgBuilder;
import hc.core.data.DataInputEvent;
import hc.core.util.HCURL;
import hc.core.util.LogManager;
import hc.server.data.DAOKeyComper;
import hc.server.data.KeyComperPanel;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.peer.RobotPeer;
import java.io.UnsupportedEncodingException;
import java.util.Vector;

import sun.awt.ComponentFactory;

public class ScreenCapturer extends PNGCapturer{
	final private Rectangle moveNewRect = new Rectangle();

	private final int screenWidth, screenHeigh;
	private int locX, locY;
	public static Object robotPeer;
	public static Robot robot;
	public KeyComper mobiUserIcons = null;
	
	static {
		try {
			robot = new Robot();
			robot.setAutoDelay(40);
		    robot.setAutoWaitForIdle(true);
			robotPeer = ((ComponentFactory) Toolkit.getDefaultToolkit())
					.createRobot(robot, GraphicsEnvironment
							.getLocalGraphicsEnvironment()
							.getDefaultScreenDevice());
		} catch (Throwable e) {
			//以上不能catch Exception
			LogManager.err("Not Found : java.awt.peer.RobotPeer(Sun API), use java.awt.Robot");
		}
	}
	
	/**
	 * 初始化扩展自定义按钮
	 */
	public void initExtMobiIcon(){
		DAOKeyComper.getInstance(this);
	}

	public ScreenCapturer(int clientWidth, int clientHeight) {
		super(clientWidth, clientHeight, false);
		
		//初始化扩展自定义按钮
		initExtMobiIcon();
		
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension screenSize = toolkit.getScreenSize();
		screenWidth = screenSize.width;
		screenHeigh = screenSize.height;
		
		setCaptureID(HCURL.REMOTE_HOME_SCREEN);
		
		hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "Screen [" + HCURL.REMOTE_HOME_SCREEN + "] start");
	
		{
			CLIENT_WIDTH = clientWidth;
			CLIENT_HEIGHT = clientHeight;
			
			locX = 0;
			int by = screenHeigh - clientHeight;
			if(by < 0){
				BOTTOM_Y = 0;
			}else{
				BOTTOM_Y = by;
			}
			int rx = screenWidth - clientWidth;
			if(rx < 0){
				MAX_RIGHT_X = 0;
			}else{
				MAX_RIGHT_X = rx;
			}
			
			locY = BOTTOM_Y;
			
			capRect.x = locX;
			capRect.y = locY;
			capRect.width = clientWidth;
			capRect.height = clientHeight;
			
			moveNewRect.x = locX;
			moveNewRect.y = locY;
			moveNewRect.width = clientWidth;
			moveNewRect.height = clientHeight;
		}
	}
	
	public boolean actionInput(DataInputEvent e){
		int type = e.getType();
		if(type == DataInputEvent.TYPE_MOUSE_MOVE){
			robot.mouseMove(e.getX(), e.getY());
			L.V = L.O ? false : LogManager.log(OP_STR + "Mouse move to (" + e.getX() + ", " + e.getY() + ")");
		}else if(type == DataInputEvent.TYPE_MOUSE_LEFT_CLICK){
			hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "Mouse left click at (" + e.getX() + ", " + e.getY() + ")");
			robot.mouseMove(e.getX(), e.getY());
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);
		}else if(type == DataInputEvent.TYPE_MOUSE_RIGHT_CLICK){
			hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "Mouse right click at (" + e.getX() + ", " + e.getY() + ")");
			robot.mouseMove(e.getX(), e.getY());
			robot.mousePress(InputEvent.BUTTON3_MASK);
			robot.mouseRelease(InputEvent.BUTTON3_MASK);			
		}else if(type == DataInputEvent.TYPE_MOUSE_DOUBLE_CLICK){
			hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "Mouse double click at (" + e.getX() + ", " + e.getY() + ")");
			
			robot.mouseMove(e.getX(), e.getY());
			
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);			
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);			
		}else if(type == DataInputEvent.TYPE_TRANS_TEXT){
			try {
				String s = e.getTextDataAsString();
				if(inputKeyStr(s) == false){
					hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "Client paste txt:[" + s + "]!");
					sendToClipboard(s);
					ctrlSomeKey(KeyEvent.VK_V);
				}else{
					hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "Client input txt:[" + s + "]!");
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}else if(type == DataInputEvent.TYPE_BACKSPACE){
			backspace();
			L.V = L.O ? false : LogManager.log(OP_STR + "Press BACKSPACE");
		}else if(type == DataInputEvent.TYPE_TAG_TRANS_TEXT_2_MOBI){
			copytxtToMobi();
		}else{
			//自定义扩展MouseIcon
			int idx = type - DataInputEvent.TYPE_TAG_TRANS_TEXT_2_MOBI;
			
			if(mobiUserIcons != null){
				Vector<Integer> vInt = mobiUserIcons.getKeys(idx);
				if(vInt == null){
					L.V = L.O ? false : LogManager.log("Unknow ext icon idx:" + type);
				}else{
					Vector<String> vString = mobiUserIcons.getKeysDesc(idx);
					
					KeyComper.keyAction(robot, vInt);
					
					String desc = vString.elementAt(0);
					for (int i = 1; i < vString.size(); i++) {
						desc += "+" + vString.elementAt(i);
					}
					L.V = L.O ? false : LogManager.log(OP_STR + "Press ext icons : " + desc);
				}
			}
		}
		
//		mttRefreshAfterInput();
		return true;
	}

	public static void type(Robot r, char character) {
        switch (character) {
        case 'a': doType(r, KeyEvent.VK_A); break;
        case 'b': doType(r, KeyEvent.VK_B); break;
        case 'c': doType(r, KeyEvent.VK_C); break;
        case 'd': doType(r, KeyEvent.VK_D); break;
        case 'e': doType(r, KeyEvent.VK_E); break;
        case 'f': doType(r, KeyEvent.VK_F); break;
        case 'g': doType(r, KeyEvent.VK_G); break;
        case 'h': doType(r, KeyEvent.VK_H); break;
        case 'i': doType(r, KeyEvent.VK_I); break;
        case 'j': doType(r, KeyEvent.VK_J); break;
        case 'k': doType(r, KeyEvent.VK_K); break;
        case 'l': doType(r, KeyEvent.VK_L); break;
        case 'm': doType(r, KeyEvent.VK_M); break;
        case 'n': doType(r, KeyEvent.VK_N); break;
        case 'o': doType(r, KeyEvent.VK_O); break;
        case 'p': doType(r, KeyEvent.VK_P); break;
        case 'q': doType(r, KeyEvent.VK_Q); break;
        case 'r': doType(r, KeyEvent.VK_R); break;
        case 's': doType(r, KeyEvent.VK_S); break;
        case 't': doType(r, KeyEvent.VK_T); break;
        case 'u': doType(r, KeyEvent.VK_U); break;
        case 'v': doType(r, KeyEvent.VK_V); break;
        case 'w': doType(r, KeyEvent.VK_W); break;
        case 'x': doType(r, KeyEvent.VK_X); break;
        case 'y': doType(r, KeyEvent.VK_Y); break;
        case 'z': doType(r, KeyEvent.VK_Z); break;
        case 'A': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_A); break;
        case 'B': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_B); break;
        case 'C': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_C); break;
        case 'D': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_D); break;
        case 'E': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_E); break;
        case 'F': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_F); break;
        case 'G': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_G); break;
        case 'H': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_H); break;
        case 'I': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_I); break;
        case 'J': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_J); break;
        case 'K': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_K); break;
        case 'L': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_L); break;
        case 'M': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_M); break;
        case 'N': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_N); break;
        case 'O': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_O); break;
        case 'P': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_P); break;
        case 'Q': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_Q); break;
        case 'R': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_R); break;
        case 'S': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_S); break;
        case 'T': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_T); break;
        case 'U': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_U); break;
        case 'V': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_V); break;
        case 'W': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_W); break;
        case 'X': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_X); break;
        case 'Y': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_Y); break;
        case 'Z': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_Z); break;
        case '`': doType(r, KeyEvent.VK_BACK_QUOTE); break;
        case '0': doType(r, KeyEvent.VK_0); break;
        case '1': doType(r, KeyEvent.VK_1); break;
        case '2': doType(r, KeyEvent.VK_2); break;
        case '3': doType(r, KeyEvent.VK_3); break;
        case '4': doType(r, KeyEvent.VK_4); break;
        case '5': doType(r, KeyEvent.VK_5); break;
        case '6': doType(r, KeyEvent.VK_6); break;
        case '7': doType(r, KeyEvent.VK_7); break;
        case '8': doType(r, KeyEvent.VK_8); break;
        case '9': doType(r, KeyEvent.VK_9); break;
        case '-': doType(r, KeyEvent.VK_MINUS); break;
        case '=': doType(r, KeyEvent.VK_EQUALS); break;
        case '~': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_QUOTE); break;
        case '!': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_1); break;
        case '@': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_2); break;
        case '#': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_3); break;
        case '$': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_4); break;
        case '%': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_5); break;
        case '^': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_6); break;
        case '&': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_7); break;
        case '*': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_8); break;
        case '(': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_9); break;
        case ')': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_0); break;
        case '_': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_MINUS); break;
        case '+': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_EQUALS); break;
        case '\t': doType(r, KeyEvent.VK_TAB); break;
        case '\n': doType(r, KeyEvent.VK_ENTER); break;
        case '[': doType(r, KeyEvent.VK_OPEN_BRACKET); break;
        case ']': doType(r, KeyEvent.VK_CLOSE_BRACKET); break;
        case '\\': doType(r, KeyEvent.VK_BACK_SLASH); break;
        case '{': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_OPEN_BRACKET); break;
        case '}': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_CLOSE_BRACKET); break;
        case '|': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_SLASH); break;
        case ';': doType(r, KeyEvent.VK_SEMICOLON); break;
        case ':': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_SEMICOLON); break;
        case '\'': doType(r, KeyEvent.VK_QUOTE); break;
        case '"': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_QUOTE); break;
        case ',': doType(r, KeyEvent.VK_COMMA); break;
        case '<': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_COMMA); break;
        case '.': doType(r, KeyEvent.VK_PERIOD); break;
        case '>': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_PERIOD); break;
        case '/': doType(r, KeyEvent.VK_SLASH); break;
        case '?': doType(r, KeyEvent.VK_SHIFT, KeyEvent.VK_SLASH); break;
        case ' ': doType(r, KeyEvent.VK_SPACE); break;
        default:
                throw new IllegalArgumentException("Cannot type character " + character);
        }
    }
	
	private static void doType(Robot r, int keyCode) {
        r.keyPress(keyCode);
        r.keyRelease(keyCode);
    }
	
	private static void doType(Robot r, int keyCode1, int keyCode2) {
        r.keyPress(keyCode1);

        r.keyPress(keyCode2);
        r.keyRelease(keyCode2);

        r.keyRelease(keyCode1);
    }
	
	private boolean inputKeyStr(String txt){
		char[] chars = txt.toCharArray();
		for (int i = 0; i < chars.length; i++) {
			final char testChar = chars[i];
			boolean isFinded = false;
			for (int j = 0; j < KeyComperPanel.DIRECT_KEYS.length; j++) {
				if(testChar == KeyComperPanel.DIRECT_KEYS[j]){
					isFinded = true;
					break;
				}
			}
			if(isFinded == false){
				//含有不适合键盘输入的字符
				return false;
			}
		}
		
		//全部符合键盘输入
		for (int i = 0; i < chars.length; i++) {
			type(robot, chars[i]);
		}
		return true;
	}
	
	private void ctrlSomeKey(int key) {
		robot.keyPress(KeyEvent.VK_CONTROL);
		robot.keyPress(key);
		robot.keyRelease(key);
		robot.keyRelease(KeyEvent.VK_CONTROL);
	}
	
	public static void sendToClipboard(String to_url) {
		Clipboard clipbd = Toolkit.getDefaultToolkit().getSystemClipboard();
		StringSelection clipString = new StringSelection(to_url);
		clipbd.setContents(clipString, clipString);
	}
	
	private static String getTxtFromClipboard(){
		Clipboard clipbd = Toolkit.getDefaultToolkit().getSystemClipboard();
		Transferable clipT = clipbd.getContents(null);
		String d = null;
		if (clipT != null) {
			// 检查内容是否是文本类型
			if (clipT.isDataFlavorSupported(DataFlavor.stringFlavor)){
				try {
					d = (String) clipT.getTransferData(DataFlavor.stringFlavor);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		if(d == null){
			return "";
		}else{
			return d.trim();
		}
	}
	
	public void backspace(){
		robot.keyPress(KeyEvent.VK_BACK_SPACE);
		robot.keyRelease(KeyEvent.VK_BACK_SPACE);
	}
	
	public void copytxtToMobi(){
		String txt = getTxtFromClipboard();
//		hc.core.L.V=hc.core.L.O?false:LogManager.log("User ready copyTxtToMobi:" + txt);
		if(txt.length() > 0){
    		DataInputEvent e = new DataInputEvent();
			try {
	    		byte[] txt_bs = txt.getBytes(IConstant.UTF_8);
	    		
	    		final byte[] txtToMobiBS = new byte[DataInputEvent.text_index + DataInputEvent.MAX_MOBI_UI_TXT_LEN];
	    		e.setBytes(txtToMobiBS);
	    		e.setType(DataInputEvent.TYPE_TRANS_TEXT);

	    		e.setTextData(txt_bs, 0, txt_bs.length);
	    		ContextManager.getContextInstance().send(
	    				MsgBuilder.E_INPUT_EVENT, txtToMobiBS, e.getLength());
			} catch (UnsupportedEncodingException e1) {
				e1.printStackTrace();
			}
		}
		hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "copyTxtToMobi:" + ((txt.length()==0)?"null":txt));
	}
	
	public void dragAndDrop(int startX, int startY, int endX, int endY){
		robot.mouseMove(startX, startY);
		robot.mousePress(InputEvent.BUTTON1_MASK);
		
		robot.mouseMove(endX, endY);
		robot.mouseRelease(InputEvent.BUTTON1_MASK);
		
//		ctrlSomeKey(KeyEvent.VK_C);
		
		hc.core.L.V=hc.core.L.O?false:LogManager.log(OP_STR + "drag from ["+startX + ", " + startY+"] to [" + endX + ", " + endY + "]");
	}

	public void moveUp(final int pixle){
		if(pixle > 0){
			L.V = L.O ? false : LogManager.log(OP_STR + "moveUp : " + pixle);
		}else{
			L.V = L.O ? false : LogManager.log(OP_STR + "moveDown : " + (-pixle));
		}
		
		moveNewRect.x = capRect.x;
		moveNewRect.y = capRect.y;

		final int newLocY = locY - pixle;
		if(newLocY < 0){
			locY = 0;
		}else if(newLocY > BOTTOM_Y){
			locY = BOTTOM_Y;
		}else{
			locY = newLocY;
		}
		
		synchronized (LOCK) {
			if(pixle > 0){
				moveNewRect.height = pixle;
				moveNewRect.y = locY;
				
				//************************
				//************************
				//************************
				//------------------------
				final int len = (CLIENT_HEIGHT - pixle) * CLIENT_WIDTH;
				int fromRowIdx = len - 1;
				for (int idxEnd = CLIENT_HEIGHT * CLIENT_WIDTH - 1; fromRowIdx >= 0;) {
					clientSnap[idxEnd--] = clientSnap[fromRowIdx--];
				}
				
//				for (int i = 0, lenM = pixle * CLIENT_WIDTH; i >= 0 && i < lenM; ) {
//					clientSnap[i++] = DEFAULT_BACK_COLOR;
//				}
			}else{
				moveNewRect.height = pixle * (-1);
				moveNewRect.y = locY + CLIENT_HEIGHT + pixle;
				
				//------------------------
				//************************
				//************************
				//************************
				final int len = (CLIENT_HEIGHT + pixle) * CLIENT_WIDTH;
				int fromRowIdx = (-pixle) * CLIENT_WIDTH;
				for (int i = 0; i < len;) {
					clientSnap[i++] = clientSnap[fromRowIdx++];
				}
				
//				final int toIdx = (CLIENT_HEIGHT + pixle) * CLIENT_WIDTH;
//				for (int i = toIdx, end = CLIENT_HEIGHT * CLIENT_WIDTH; i >= 0 && i < end; ) {
//					clientSnap[i++] = DEFAULT_BACK_COLOR;
//				}
			}
	
			capRect.y = locY;
			
			moveNewRect.width = CLIENT_WIDTH;
	//		将新出生的空白块，发出
			sendPNG(moveNewRect, false);
		}
	}
	
	public void moveRight(final int pixle){
		if(pixle > 0){
			L.V = L.O ? false : LogManager.log(OP_STR + "moveRight : " + pixle);
		}else{
			L.V = L.O ? false : LogManager.log(OP_STR + "moveLeft : " + (-pixle));
		}
		
		moveNewRect.x = capRect.x;
		moveNewRect.y = capRect.y;
		
		final int newLocX = locX + pixle;
		if(newLocX < 0){
			locX = 0;
		}else if(newLocX > MAX_RIGHT_X){
			locX = MAX_RIGHT_X;
		}else{
			locX = newLocX;
		}

		synchronized (LOCK) {		
			if(pixle > 0){
				moveNewRect.width = pixle;
				moveNewRect.x = locX + CLIENT_WIDTH - pixle;

				for (int row = 0, RowLen = CLIENT_HEIGHT; row < RowLen; row++) {
					final int idxR = row * CLIENT_WIDTH;
					int idxM = idxR + pixle;
					//--********************
					for (int x = idxR, end = idxR + CLIENT_WIDTH - pixle; x >= 0 && x < end;) {
						clientSnap[x++] = clientSnap[idxM++];
					}
//					for (int end = idxR + CLIENT_WIDTH, i = end - pixle; i >= 0 && i < end; i++) {
//						clientSnap[i] = DEFAULT_BACK_COLOR;
//					}
				}
			}else{
				moveNewRect.width = pixle * (-1);
				moveNewRect.x = locX;

				for (int row = 0, RowLen = CLIENT_HEIGHT; row < RowLen; row++) {
					final int idxR = row * CLIENT_WIDTH;
					int idxM = idxR + CLIENT_WIDTH + pixle - 1;
					//********************--
					for (int x = idxR + CLIENT_WIDTH - 1; idxM >= idxR;) {
						clientSnap[x--] = clientSnap[idxM--];
					}
//					for (int i = idxR, len = idxR-pixle; i >= 0 && i < len; i++) {
//						clientSnap[i] = DEFAULT_BACK_COLOR;
//					}
				}
			}
			
			capRect.x = locX;
	
			moveNewRect.height = CLIENT_HEIGHT;
			//将新出生的空白块，发出
			sendPNG(moveNewRect, false);
		}
	}
	
	private final int BOTTOM_Y, MAX_RIGHT_X;
	private final int CLIENT_WIDTH, CLIENT_HEIGHT;
	
	public void refreshRectange(final int x, final int y){	
		capRect.x = x;
		capRect.y = y;
		
		locX = x;
		locY = y;
		
		moveNewRect.width = CLIENT_WIDTH;
		moveNewRect.height = CLIENT_HEIGHT;
		
		sendPNG(capRect, false);
	}
	
	/**
	 * 本方法未来将由自动定时刷新对比来替换
	 */
//	private void mttRefreshAfterInput(){
//		robot.delay(200);
//		sendPNG(capRect, capRect.x, capRect.y, true);
//	}	

	@Override
	public int grabImage(final Rectangle bc, final int[] rgb){
		final int[] out = (robotPeer!=null)?
				((RobotPeer)robotPeer).getRGBPixels(bc):
				robot.createScreenCapture(bc).getRGB(
						0, 0, bc.width, bc.height, null, 0, bc.width);
		final int length = bc.width * bc.height;
		System.arraycopy(out, 0, rgb, 0, length);
		return length;
	}

	public int getScreenWidth() {
		return screenWidth;
	}

	public int getScreenHeigh() {
		return screenHeigh;
	}

	@Override
	public void onExit(){
		super.onExit();
	}

	@Override
	public void onStart() {
		super.start();
	}

	@Override
	public void onPause() {
		enableStopCap(true);
	}

	@Override
	public void onResume() {
		enableStopCap(false);
	}
}
